//https://leetcode.cn/problems/kth-node-from-end-of-list-lcci/description/
//返回链表的倒数第k个结点
//实现一种算法，找出单向链表中倒数第 k 个节点。返回该节点的值。

typedef struct ListNode ListNode;

int kthToLast(struct ListNode* head, int k){
    ListNode* slow = head;
    ListNode* fast = head;
    for(int i = 0; i < k; i++)
    {
        fast = fast->next;
    }
    while(fast)
    {
        slow = slow->next;
        fast = fast->next;
    }
    return slow->val;
}
